 import { Button, Form, Input, message } from "antd"
import Layout from "../core/Layout"
import axios from 'axios'
import { API } from "../../config"
import { isAuth } from "../../helpers/auth"
import { Link } from "react-router-dom"
 
 export default function AddCategory() {
     const handleOnFinish = async value => {
         if (value.name) {
             await axios.post(`${API}/category/create/${isAuth().user._id}`, value, {
                 headers: {
                     Authorization: `Bearer ${isAuth().token}`
                 }
             }).then(res => {
                 message.success(`${res.data.name} 添加成功`) 
             })
         }
     }
     return <Layout title='添加分类'>
         <Form onFinish={handleOnFinish}>
             <Form.Item label='分类名称' name='name'>
                 <Input />
             </Form.Item>
             <Form.Item>
                 <Button type="primary" htmlType='submit'>添加分类</Button>
             </Form.Item>
         </Form>
         <Button>
             <Link to='/admin/dashboard'>返回 dashboard</Link>
         </Button>
     </Layout>
 }